#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>

using namespace std;


struct ListNode 
{
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(nullptr) {}
};
 
class Solution {
public:
    ListNode* reverseln(ListNode* head) {
        ListNode* newhead = new ListNode(0);
        ListNode* cur = head;

        while (cur) {
            ListNode* next = cur->next;
            cur->next = newhead->next;
            newhead->next = cur;
            cur = next;
        }
        return newhead->next;
    }

    ListNode* addInList(ListNode* head1, ListNode* head2) {
        head1 = reverseln(head1);
        head2 = reverseln(head2);

        int t = 0;
        ListNode* ret = new ListNode(0);
        ListNode* cur1 = head1;
        ListNode* cur2 = head2;
        ListNode* prev = ret;
        while (cur1 || cur2 || t) {
            if (cur1) {
                t += cur1->val;
                cur1 = cur1->next;
            }
            if (cur2) {
                t += cur2->val;
                cur2 = cur2->next;
            }
            prev = prev->next = new ListNode(t % 10);

            t /= 10;
        }
        return reverseln(ret->next);
    }
};


class Solution {
public:
    string solve(string s, string t)
    {
        string ret;

        int i = s.size() - 1, j = t.size() - 1;
        int tmp = 0;
        while (i >= 0 || j >= 0 || tmp != 0)
        {
            if (i >= 0) tmp += s[i--] - '0';
            if (j >= 0) tmp += t[j--] - '0';
            ret += tmp % 10 + '0';
            tmp /= 10;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};